import { token } from '@/types/data'

const TOKEN_KEY = 'geek-app-66'

// 获取 token
export function getToken (): token {
  if (localStorage.getItem(TOKEN_KEY)) {
    return JSON.parse(localStorage.getItem(TOKEN_KEY) || '{}')
  }
  return {
    token: '',
    refresh_token: ''
  }
}

// 设置 token
export function setToken (data: token): void {
  localStorage.setItem(TOKEN_KEY, JSON.stringify(data))
}

// 移除 token
export function removeToken (): void {
  localStorage.removeItem(TOKEN_KEY)
}

// 判断是否登录（授权）
export function hasToken (): boolean {
  return !!getToken().token
}
